/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SysAguas.visao;

import SysAguas.controle.Erro;
import SysAguas.controle.TelaPrincipalControle;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

/**
 *
 * @author Heitor
 */
public class TelaPrincipal extends JFrame {

    private JMenu menuPrincipal, menuQuartos, menuSobre, 
            menuReserva, menuPagamento,menuRelatorio;
    private JMenuBar jMenuBar;
    private JMenuItem itemMenuPagamento, itemMenuSair, itemMenuReservaCriar, itemMenuQuartos,
            itemMenuReservaBuscar, itemMenuSobre, itemMenuHome, itemMenuGeranciarQuartos,
            itemMenuReportHospede,itemMenuReportQuartos;
    private PanelPrincipal panelPrincipal;
 //   private DialogCadastrarQuartos cadastrarQuartosDialog;
 //   private DialogAtualizarReserva atualizarReservaDialog;
    private PanelCadastrarReserva panelCadastrarReserva;
    private PanelConsultarReserva panelConsultarReserva;

    public TelaPrincipal() {
        this.setTitle("SysAguas");
        //    this.setResizable(false);
        //  WindowUtilities.setNinbusLookAndFeel();

        panelPrincipal = new PanelPrincipal();
        panelCadastrarReserva = new PanelCadastrarReserva();
        panelCadastrarReserva.montar();
        panelConsultarReserva = new PanelConsultarReserva();
        panelConsultarReserva.montarJanelaBusca();
        panelCadastrarReserva.setVisible(false);
        panelConsultarReserva.setVisible(false);

        menuPrincipal = new JMenu("Principal");
        menuPrincipal.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        menuQuartos = new JMenu("Quartos");
        menuQuartos.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        menuSobre = new JMenu("Sobre");
        menuSobre.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        menuReserva = new JMenu("Reserva");
        menuReserva.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        menuPagamento = new JMenu("Pagamento");
        menuPagamento.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        menuRelatorio = new JMenu("Relatorio");
        menuRelatorio.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        
        jMenuBar = new JMenuBar();
        jMenuBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        /******************************************************************/
        itemMenuQuartos = new JMenuItem("Cadastrar Quartos");
        itemMenuQuartos.addActionListener(new TelaPrincipalControle(this, panelPrincipal, panelCadastrarReserva, panelConsultarReserva));

        itemMenuGeranciarQuartos = new JMenuItem("Alterar Quartos");
        itemMenuGeranciarQuartos.addActionListener(new TelaPrincipalControle(this, panelPrincipal, panelCadastrarReserva, panelConsultarReserva));

        itemMenuSobre = new JMenuItem("Sobre...");
        itemMenuSobre.addActionListener(new TelaPrincipalControle(this, panelPrincipal, panelCadastrarReserva, panelConsultarReserva));

        itemMenuHome = new JMenuItem("Home");
        itemMenuHome.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        itemMenuHome.addActionListener(new TelaPrincipalControle(this, panelPrincipal, panelCadastrarReserva, panelConsultarReserva));

        itemMenuSair = new JMenuItem("Sair");
        itemMenuSair.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        itemMenuSair.addActionListener(new TelaPrincipalControle(this, panelPrincipal, panelCadastrarReserva, panelConsultarReserva));

        itemMenuPagamento = new JMenuItem("Pagamento");
        itemMenuPagamento.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        itemMenuPagamento.addActionListener(new Erro());

        itemMenuReportHospede = new JMenuItem("Hospede");
        itemMenuReportHospede.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        itemMenuReportHospede.addActionListener(new Erro());

        itemMenuReportQuartos = new JMenuItem("Quartos");
        itemMenuReportQuartos.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        itemMenuReportQuartos.addActionListener(new Erro());

        itemMenuReservaCriar = new JMenuItem("Criar Reserva");
        itemMenuReservaCriar.addActionListener(new TelaPrincipalControle(this, panelPrincipal, panelCadastrarReserva, panelConsultarReserva));
        itemMenuReservaCriar.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        itemMenuReservaBuscar = new JMenuItem("Consultar Reserva");
        itemMenuReservaBuscar.addActionListener(new TelaPrincipalControle(this, panelPrincipal, panelCadastrarReserva, panelConsultarReserva));
        itemMenuReservaBuscar.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));





    }

    public void montarJanela() {

        this.setLayout(new BorderLayout(2, 2));


        menuPrincipal.add(itemMenuHome);
        menuPrincipal.add(itemMenuSair);
        jMenuBar.add(menuPrincipal);

        menuReserva.add(itemMenuReservaBuscar);
        menuReserva.add(itemMenuReservaCriar);
        jMenuBar.add(menuReserva);

        menuQuartos.add(itemMenuGeranciarQuartos);
        menuQuartos.add(itemMenuQuartos);

        jMenuBar.add(menuQuartos);

        menuPagamento.add(itemMenuPagamento);
        jMenuBar.add(menuPagamento);

        menuRelatorio.add(itemMenuReportHospede);
        menuRelatorio.add(itemMenuReportQuartos);
        jMenuBar.add(menuRelatorio);

        menuSobre.add(itemMenuSobre);
        jMenuBar.add(menuSobre);


        this.setJMenuBar(jMenuBar);



        this.add(panelPrincipal, BorderLayout.CENTER);
        panelPrincipal.montarPanelPrincipal();

        this.setSize(1000, 600);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);


    }

    /*

    if (e.getSource() == itemMenuSair) {

    System.exit(0);

    /*        } if (e.getSource()== consultar){

    TelaBuscarReserva c = new TelaBuscarReserva();
    c.montarJanelaBusca();
     */
    /*
    if (e.getSource() == itemMenuQuartos) {

    cadastrarQuartosDialog = new DialogCadastrarQuartos(this, "Cadastro de Quartos", true);
    cadastrarQuartosDialog.montarCadastrarQuartos();



    }
    if (e.getSource() == itemMenuHome) {

    if (panelCadastrarReserva != null) {
    panelCadastrarReserva.setVisible(false);
    this.remove(panelCadastrarReserva);
    }
    if (panelConsultarReserva != null) {
    panelConsultarReserva.setVisible(false);
    this.remove(panelConsultarReserva);
    }
    this.add(panelPrincipal, BorderLayout.CENTER);
    //        panelPrincipal.montarPanelPrincipal();
    panelPrincipal.setVisible(true);

    }
    if (e.getSource() == itemMenuSobre) {
    String texto = "<HTML><i>SysAguas</i> <P>"
    + "Codificado por Heitor Lima <P>"
    + "e Diego Francisco Ribeiro </HTML>";
    JOptionPane.showMessageDialog(this, texto);

    }

    if (e.getSource() == itemMenuReservaCriar) {
    if (panelCadastrarReserva != null) {
    if (panelCadastrarReserva.isVisible()) {
    System.out.println("criou panel criar 1");
    return;

    } else {
    this.add(panelCadastrarReserva, BorderLayout.CENTER);
    panelCadastrarReserva.setVisible(true);
    }

    }
    if (panelPrincipal != null) {
    panelPrincipal.setVisible(false);
    this.remove(panelPrincipal);
    }
    if (panelConsultarReserva != null) {
    panelConsultarReserva.setVisible(false);
    this.remove(panelConsultarReserva);
    }

    if (panelCadastrarReserva == null) {
    System.out.println("criou panel criar 2");

    panelCadastrarReserva = new PanelCadastrarReserva();
    this.add(panelCadastrarReserva, BorderLayout.CENTER);
    panelCadastrarReserva.montar();
    }
    }

    if (e.getSource() == itemMenuReservaBuscar) {

    if (panelConsultarReserva != null) {
    if (panelConsultarReserva.isVisible()) {
    System.out.println("criou panel buscar 1");
    return;
    } else {

    this.add(panelConsultarReserva, BorderLayout.CENTER);
    panelConsultarReserva.setVisible(true);
    }

    }
    if (panelPrincipal != null) {
    panelPrincipal.setVisible(false);
    this.remove(panelPrincipal);

    }
    if (panelCadastrarReserva != null) {
    panelCadastrarReserva.setVisible(false);
    this.remove(panelCadastrarReserva);

    }
    if(panelConsultarReserva == null){
    System.out.println("criou panel buscar 2");
    panelConsultarReserva = new PanelConsultarReserva();
    this.add(panelConsultarReserva, BorderLayout.CENTER);
    panelConsultarReserva.montarJanelaBusca();
    }


    }/*if(e.getSource() == panelConsultarReserva.getButtonAtualizar()){

    atualizarReservaDialog = new DialogAtualizarReserva(this, "Atualizar Reserva",true);
    atualizarReservaDialog.montaa();
     */
    public PanelPrincipal getPanelPrincipal() {
        return panelPrincipal;
    }

    /*    public DialogAtualizarReserva getAtualizarReservaDialog() {
    return atualizarReservaDialog;
    }

    public DialogCadastrarQuartos getCadastrarQuartosDialog() {
    return cadastrarQuartosDialog;
    }
     */
    public JMenuItem getItemMenuHome() {
        return itemMenuHome;
    }

    public JMenuItem getItemMenuQuartos() {
        return itemMenuQuartos;
    }

    public JMenuItem getItemMenuReservaBuscar() {
        return itemMenuReservaBuscar;
    }

    public JMenuItem getItemMenuReservaCriar() {
        return itemMenuReservaCriar;
    }

    public JMenuItem getItemMenuSair() {
        return itemMenuSair;
    }

    public JMenuItem getItemMenuSobre() {
        return itemMenuSobre;
    }

    public JMenuItem getItemMenuGeranciarQuartos() {
        return itemMenuGeranciarQuartos;
    }

    /*  public PanelCadastrarReserva getPanelCadastrarReserva() {
    return panelCadastrarReserva;
    }

    public PanelConsultarReserva getPanelConsultarReserva() {
    return panelConsultarReserva;
    }
     */
}
